#ifndef _AC_CALYPSO_INSERTPAGE
#define _AC_CALYPSO_INSERTPAGE

#include "MainWindow.h"


namespace AirCrash {
namespace Calypso {

class PhotoThread : public QThread {
	Q_OBJECT

	volatile bool mInterrupted;

public:
	PhotoThread();
	~PhotoThread();

	void run();
	void interrupt();

signals:
	void imageReady(QIcon icon, QString fileName);
};

class InsertItemThread : public QThread {
	Q_OBJECT

	QString mSummary,
		mImagePath;
	QImage mImage;
	int mFriday,
		mSaturday,
		mSunday;
	bool mJackpot;

public:
	InsertItemThread();
	~InsertItemThread();

	void insertItem(const QString& summary, const QString& imagePath, int friday, int saturday, int sunday, bool jackpot);
	void insertItem(const QString& summary, const QImage& image, int friday, int saturday, int sunday, bool jackpot);
	void run();

signals:
	void itemInserted();
};

class GenerateCodesThread : public QThread {
	Q_OBJECT

public:
	GenerateCodesThread();
	~GenerateCodesThread();

	void run();

signals:
	void codesGenerated();
};

}
}

class InsertPage : public QWidget {
	Q_OBJECT

	Ui::MainWindowClass * mUi;

	QIntValidator * mValidator;
	AirCrash::Calypso::PhotoThread * mPhotoThread;
	AirCrash::Calypso::InsertItemThread * mInsertThread;
	AirCrash::Calypso::GenerateCodesThread * mGenerateThread;

protected:
	void keyPressEvent(QKeyEvent *);
	void paintEvent(QPaintEvent *);
	void showEvent(QShowEvent *);
	void hideEvent(QHideEvent *);

public:
	InsertPage();
	~InsertPage();

	void setUi(Ui::MainWindowClass * ui);

public slots:
	void imageReady(QIcon icon, QString fileName);
	void insert();

	void generateCodes();
	void refreshImages();

	void codesGenerated();
	void itemInserted();

	void fillInsertPage(int friday, int saturday, int sunday, QString summary, bool jackpot);
	void createItem();

	void addPhotos();

signals:
	void nextItem();
};

#endif